//
// Created by 16586 on 2024/8/14.
//

#ifndef TSAVPLAYER_OBOERENDER_H
#define TSAVPLAYER_OBOERENDER_H

#include "oboe/oboe.h"
#include "LogUtil.h"

#include <thread>

#include "AudioRender.h"
#include <queue>
#include <string>
using namespace std;
#define MAX_QUEUE_BUFFER_SIZE 3
class OboeRender:public AudioRender,public oboe::AudioStreamDataCallback {
private:
    volatile bool m_Exit = false;

    oboe::AudioStreamBuilder builder;
    oboe::Result result;
    std::shared_ptr<oboe::AudioStream> mStream;
public:
    OboeRender();
    virtual ~OboeRender(){};

    void ClearAudioCache();
    void UnInit();


    void RenderAudioFrame(uint8_t *pData, int dataSize) override;

    static void CreateSLWaitingThread(OboeRender *openSlRender);
    void StartRender();

    int GetAudioFrameQueueSize();
    oboe::DataCallbackResult onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames) override;

    const int kSampleRate=44100;
    const int channelCount=2;
    virtual void Init();
    thread *m_thread;

    condition_variable m_Cond;
    mutex m_Mutex;

    queue<AudioFrame *> m_AudioFrameQueue;
};


#endif //TSAVPLAYER_OBOERENDER_H
